package com.sdcx.agrobank.ui.my_activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.sdcx.agrobank.R;
import com.sdcx.agrobank.dialog.ChangeSexDia;

public class detailActivity extends AppCompatActivity {

    private ImageView back;
    private LinearLayout sex;
    private TextView tvsex, enter;
    private SPUtils utils;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        utils = SPUtils.getInstance();
        back = findViewById(R.id.back);
        sex = findViewById(R.id.change_sex);
        enter = findViewById(R.id.enter);
        tvsex = findViewById(R.id.tv_sex);
        EditText xingming = findViewById(R.id.xingming);
        EditText guoji = findViewById(R.id.guoji);
        EditText shenfenzheng = findViewById(R.id.shenfenzheng);
        EditText daoqi = findViewById(R.id.daoqi);
        EditText yidong = findViewById(R.id.yidong);
        EditText youxiang = findViewById(R.id.youxiang);
        EditText guding = findViewById(R.id.guding);
        EditText dizhi = findViewById(R.id.dizhi);
        EditText youbian = findViewById(R.id.youbian);
        EditText zhiye1 = findViewById(R.id.zhiye1);
        EditText zhiye2 = findViewById(R.id.zhiye2);
        EditText zhiye3 = findViewById(R.id.zhiye3);
        String xingming1 = utils.getString("xingming");
        String sex1 = utils.getString("sex");
        String guoji1 = utils.getString("guoji");
        String shenfenzheng1 = utils.getString("shenfenzheng");
        String daoqi1 = utils.getString("daoqi");
        String yidong1 = utils.getString("yidong");
        String youxiang1 = utils.getString("youxiang");
        String guding1 = utils.getString("guding");
        String dizhi1 = utils.getString("dizhi");
        String youbian1 = utils.getString("youbian");
        String zhiye11 = utils.getString("zhiye1");
        String zhiye21 = utils.getString("zhiye2");
        String zhiye31 = utils.getString("zhiye3");
        xingming.setText(xingming1);
        tvsex.setText(sex1);
        guoji.setText(guoji1);
        shenfenzheng.setText(shenfenzheng1);
        daoqi.setText(daoqi1);
        yidong.setText(yidong1);
        youxiang.setText(youxiang1);
        guding.setText(guding1);
        dizhi.setText(dizhi1);
        youbian.setText(youbian1);
        zhiye1.setText(zhiye11);
        zhiye2.setText(zhiye21);
        zhiye3.setText(zhiye31);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        enter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                utils.put("xingming", xingming.getText().toString());
                utils.put("sex", tvsex.getText().toString());
                utils.put("guoji", guoji.getText().toString());
                utils.put("shenfenzheng", shenfenzheng.getText().toString());
                utils.put("daoqi", daoqi.getText().toString());
                utils.put("yidong", yidong.getText().toString());
                utils.put("youxiang", youxiang.getText().toString());
                utils.put("guding", guding.getText().toString());
                utils.put("dizhi", dizhi.getText().toString());
                utils.put("youbian", youbian.getText().toString());
                utils.put("zhiye1", zhiye1.getText().toString());
                utils.put("zhiye2", zhiye2.getText().toString());
                utils.put("zhiye3", zhiye3.getText().toString());

                ToastUtils.showLong("修改成功");
                finish();
            }
        });
        sex.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ChangeSexDia dia = new ChangeSexDia(detailActivity.this, R.style.DialogTheme);
                Window window = dia.getWindow();
                window.setGravity(Gravity.CENTER);
                window.setWindowAnimations(R.style.Animation_Design_BottomSheetDialog);
                dia.show();
                Display display = getWindowManager().getDefaultDisplay();
                WindowManager.LayoutParams params = dia.getWindow().getAttributes();
                params.width = (display.getWidth() * 1);
                window.setAttributes(params);
                dia.setOnClickListener(new ChangeSexDia.onClickListener() {
                    @Override
                    public void onItemClickListener(int type) {
                        if (type == 1) {
                            tvsex.setText("男");

                        } else {
                            tvsex.setText("女");
                        }
                    }
                });
            }
        });
    }
}